import akka.actor.{Actor, ActorRef, ActorSystem, Props}

/**
 * @program: day0304_3
 * @description: 尽信书，则不如无书
 * @author: CoreDao
 * @create: 2021-03-04 19:48
 * */
/**
 * 模拟多个actor之间的相互通信
 */
class MyActor1 extends Actor{
  override def receive: Receive = {
    case msg:String =>{
      println(msg + " 1: " + self.path.name)
      println("已读")
      Thread.sleep(2000)
      sender() ! msg
    }
    case _:Int =>{
      println("number"+ " 1: "+ self.path.name)
    }
    case _ =>{
      println("no"+ " 1: "+ self.path.name)
    }
  }
}

class MyActor2(actor11: ActorRef) extends Actor{
  override def receive: Receive = {
    case msg:String =>{
      println(msg + " 2: " + self.path.name)
      Thread.sleep(2000)
      actor11 ! msg
    }
    case _ =>{
      println("ohohoh"+ " 2: "+ self.path.name)
    }

  }
}

object ActorTest2 extends App {
  private val system: ActorSystem = ActorSystem("system")

  private val actor11: ActorRef = system.actorOf(Props[MyActor1], "actor11")

  private val actor21: ActorRef = system.actorOf(Props(new MyActor2(actor11)), "actor21")

  actor21 ! "你好,薛女士"



}
